@extends('admin.public.admin')
@section('main')

<div class="mws-panel grid_8">
	<div class="mws-panel-header">
    	<span><i class="icon-table"></i>标签列表</span>
    </div>
    <div class="mws-panel-body no-padding">
        <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
             <form method="get" action="/admin/tags">

                      <div id="DataTables_Table_1_length" class="dataTables_length">
               
                        <label>显示 
                            <select size="1" name="count" aria-controls="DataTables_Table_1">
                                <option value="10" @if(!empty($request['count']) && $request['count'] == 10) selected @endif>10</option>
                                <option value="20" @if(!empty($request['count']) && $request['count'] == 20) selected @endif>20</option>
                                <option value="30" @if(!empty($request['count']) && $request['count'] == 30) selected @endif>30</option>
                                <option value="50" @if(!empty($request['count']) && $request['count'] == 50) selected @endif>50</option>
                            </select> 
                        条
                        </label>
                      </div>

            <div class="dataTables_filter" id="DataTables_Table_1_filter">
                    <label>
                        搜索: <input type="text" name="search" value="{{$request['search'] or ''}}" aria-controls="DataTables_Table_1">
                            <input type="submit" class="btn btn-success btn-xs" value="搜索">
                    </label>
            </div>
            </form>
        <table class="mws-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>所属分类</th>
                    <th>标签名称</th>
                    <th>关键字</th>
                    <th>创建时间</th>
                    <th>是否启用</th> 
                    <th>添加属性</th>             
                    <th>操作</th>
                </tr>
            </thead>

            <tbody>
             <?php 
                  $num=0;
                ?>
            	@foreach($data as $k=>$v)
                <tr>
                    <td>{{++$num}}</td>

                     <?php

                     $len = substr_count($v['path'],',');
                     ?>
		
                    <td>{{str_repeat('|----',$len-1).$v['typename']}}</td>

                    <td><a href="javascript:;" onclick="show({{$v['id']}})" data-toggle="modal" data-target="#show" class="btn btn-primary">{{$v['tagname']}}</a></td>


                    <td>{{$v['keywords']}}</td>

               
					<td>{{date('Y-m-d H:i:s',$v['createtime'])}}</td>

                @if($v['status'])
					<td align="center"><span class="btn btn-success">是</span></td>

				@else
					<td align="center"><span class="btn btn-danger">否</span></td>
					
				@endif
				 
				
					<!-- <td align="center"><a href="/admin/tags/create?id={{$v['id']}}" class="btn btn-primary ">添加属性</a></td> -->
					<!-- <a href="javascript:;" data-toggle="modal" data-target="#add" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> 添加管理员</a> -->
					<!-- <td align="center"><a href="javascript:;" onclick="" data-toggle="modal" data-target="#add" class=class="btn btn-primary ">添加属性</a></td> -->
					<td><a href="javascript:;" onclick="add({{$v['id']}})" data-toggle="modal" data-target="#add" class="btn btn-primary">添加属性</a></td>
				
                    <td align="center" >
           　
                    	&nbsp;&nbsp;
                    	<a href="/admin/tags/{{$v['id']}}/edit"  class="icon-pencil-2" title="修改"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>

       


             <!-- 分页 -->
              <div id="page_page">
                   {!! $data->appends($request)->render()!!}
              </div>
        </div>
    </div>
</div>

<!-- 添加页面模态框 -->
<div class="modal fade" id="add">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				<h4 class="modal-title">添加属性</h4>
			</div>
			<div class="modal-body" id="body">
				
			</div>
			
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!-- 显示属性模态框 -->
<div class="modal fade" id="show">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				<h4 class="modal-title">属性值列表</h4>
			</div>
			<div class="modal-body" id="attr">
				
			</div>
			
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<script>

	//添加

	function add(id){
		// 发送ajax请求
		$.get("/admin/tags/addAttr/"+id,{},function(data){

			if (data) {

				$("#body").html(data);
			};

		});

	}

	//添加方法
	function save(){
		// 表单序列化
		str=$("#formEdit").serialize();

		// 提交到下一个页面

		$.post("/admin/tags/insertAttr",{str:str,"_method":'post','_token':'{{csrf_token()}}'},function(data){

			// 判断data
			if (data==1) {
				
				alert("添加成功");
				window.location.reload();

			}else{
				$("#attrInfo").html('添加失败');
			}
		});
	}


	//属性展示页面

	function show(id){
		// 发送ajax请求
		$.get("/admin/tags/showAttr/"+id,{},function(data){

			if (data) {

				$("#attr").html(data);
			};

		});


	}
	
</script>


@endsection